using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;

namespace Thinxoft.HttpLib
{
	/// <summary>
	/// Summary description for HttpCookiesCollection.
	/// </summary>
	public class HttpCookies : MarshalByRefObject,IHttpCookies
	{
		Hashtable cookies;
		public HttpCookies(string[] cookies)
		{
			this.cookies = new Hashtable();
			foreach(string cookie in cookies)
			{
				string[] parts  = cookie.Split("=".ToCharArray());
				Add(parts[0].Trim(),parts[1].Trim());
			}
			
		}

		public HttpCookies()
		{
			this.cookies = new Hashtable();
		}

		public int Count
		{
			get
			{
				return this.cookies.Count;
			}
		}

		public bool HasCookie(string cookie)
		{
			return this.cookies.ContainsKey(cookie);
		}

		public void Add(string name, string val)
		{
			if(cookies.ContainsKey(name))
			{
				cookies[name] = val;
			}else
				cookies.Add(name,val);
		}

		public string this[string key]
		{
			get
			{
				return (string)this.cookies[key];
			}
		}

		public IEnumerator GetEnumerator()
		{
			return this.cookies.Keys.GetEnumerator();
		}
	}
}
